using System.Collections.Generic;
using Kopernikus.Parsing.GenericLexing;
using Kopernikus.Parsing.Lexing;
using NUnit.Framework;

namespace Kopernikus.Parsing.Tests.GenericLexing
{
    [TestFixture]
    public class TestBadInput
    {
        [LexIgnore("\\s+")]
        private class L
        {
            [LexDefault("a", "b", "c")]
            public string t(LexerMatch m)
            {
                return m.Value;
            }
        }

        [Test]
        public void Test()
        {
            GenericLexer<L, string> lexer = GenericLexer<L, string>.Create(new L());

            IEnumerator<string> e = lexer.Scan("a b c x").GetEnumerator();

            foreach (char c in "abc".ToCharArray())
            {
                e.MoveNext();
                Assert.AreEqual(c.ToString(), e.Current);
            }

            try
            {
                e.MoveNext();
                Assert.Fail();
            }
            catch (InvalidInputException)
            {
            }
        }
    }
}